#ifndef _OHAI_LOG_H_
#define _OHAI_LOG_H_

/* A simple multi-target logger.
 *
 * Writes formatted logs to multiple registered FILE streams. This is to allow
 * for log output both to users and to private (rather than syslog) files.
 *
 * int main(void) {
 *   FILE *fp;
 *
 *   log_register(stderr);
 *
 *   log_err("Oh dear, %s has only %d pence left", "the prince", 5);
 *   log_debug("Before debugging, not printed");
 *   log_set_debug();
 *
 *   fp = fopen("file-based.log", "a");
 *   log_register(fp);
 *
 *   log_debug("This debugging messages is printed to stderr and the file.");
 *
 *   fclose(fp);
 *   return 0;
 * }
 *
 * Copyright 2008 Cian Synnott.
 * 
 * $Id: log.h 19 2009-11-27 20:46:48Z cian $
 */

#include <stdio.h>

/* Registers a file stream as a log destination.
 *
 * Args:
 * - stream: FILE object to log errors to
 * Returns:
 * - integer 0 on success or -1 on failure
 */
int log_register(FILE *stream);

/* Unregisters a registered file stream as a log destination.
 *
 * Args:
 * - stream: FILE object to remove
 * Returns:
 * - integer 0 on success or -1 on failure
 */
int log_unregister(FILE *stream);

/* Set log level to debug. Normally, only info, warn and err levels are logged.
 */
void log_set_debug(void);

/* Log messages at defined level, printf style.
 * Note that log_errx() also exits with the defined return value to the OS 
 */
void log_err(char *fmt, ...);
void log_errx(int retval, char *fmt, ...);
void log_warn(char *fmt, ...);
void log_info(char *fmt, ...);
void log_debug(char *fmt, ...);

#endif /* _OHAI_LOG_H_ */
